<%--
  Created by IntelliJ IDEA.
  User: 10106
  Date: 2024/12/5
  Time: 14:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>异步提交商品</title>
  </head>
  <body>
  <form id="products">
    <table border="1">
      <tr>
        <td>商品id</td>
        <td>商品名称</td>
        <td>提交</td>
      </tr>
      <tr>
        <td><input name="proId" value="1" id="proId"></td>
        <td><input name="proName" value="三文鱼" id="proName"></td>
        <td><input name="button" value="提交单个商品" onclick="sumbmitProduct()"></td>
      </tr>
      <tr>
        <td><input name="proId" value="2" id="proId2"></td>
        <td><input name="proName" value="红牛" id="proName2"></td>
        <td><input name="button" value="提交多个商品" onclick="submitProducts()"></td>
      </tr>
    </table>
  </form>
  <script src="static/js/jquery.min.js"></script>
  <script>
    function sumbmitProduct(){
      var proId = $("#proId").val();
      var proName = $("#proName").val();
      $.ajax({
        url: "/getProduct",//请求网址
        type:"post",
        data:JSON.stringify({proId,proName:proName}),
        contentType:"application/json;charset=UTF-8",
        dataType:"json",
        success:function (response) {
          alert(response);
        }
      });
    }
    function submitProducts(){
      var pro1 = {proId:$("#proId") .val(),proName:$("#proName").val()}
      var pro2 = {proId:$("#proId2") .val(),proName:$("#proName2").val()}
      $.ajax({//get post
        url: "/getProductList",//请求网址
        type:"post",
        data:JSON.stringify([pro1,pro2]),
        contentType:"application/json;charset=UTF-8",
        dataType:"json",
        success:function (response) {
          alert(response);
        }
      });
    }
  </script>
  </body>
</html>
